# -*- coding:utf-8 -*-
# @Time : 21-11-5 上午2:46 
# @Author : zdy
# @File : UIModifyPsw.py
# desc:
from UI.ModifyPsw import Ui_ModifyPsw
from importQT import *
from Class.Devices import *
from Class.UserInfo import *

class UIModifyPsw(QDialog, Ui_ModifyPsw):
    def __init__(self):
        super(UIModifyPsw, self).__init__()
        self.setupUi(self)
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setFixedSize(self.width(), self.height())
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.applyResource()
        self.btnSave.clicked.connect(self.btnSave_clicked)
        self.btnCancel.clicked.connect(self.btnCancel_clicked)

    def applyResource(self):
        self.setWindowIcon(getIcon())

    def btnSave_clicked(self):
        """判断当前密码是否正确，若正确则更新新密码，关闭窗口"""
        if self.txtPswNow.text() == currentuser.psw:
            currentuser.psw = self.txtPswNew.text()
            currentUsers[currentuser.name] = currentuser
            savecurrentUsers()
            self.accept()
            self.close()
        else:
            QMessageBox.information(self,"提示", "当前密码错误")

    def btnCancel_clicked(self):
        self.close()